
<script type="text/javascript">
    $(document).ready(function(){
        $('#bt_flow').click(function(){
            var property = 'followProduct';
            var func = '';
            var fullname = $('#tb_fullname').val();
            var homepage = $('#tb_homepage').val();
            var product = $('#tb_flowproduct').val();
            var product_uri = $('#tb_uriproduct').val();
            var flow_user = $('#tb_flowuser').val();
            var flow_product = '';
            var sflow = $('#bt_flow').text();
            if(sflow == 'THEO DÕI SẢN PHẨM'){
                flow_product = product.trim() + product_uri.trim()+';';
                $('#bt_flow').text('HỦY THEO DÕI');
                $('#img_flow').show();
                $('#tb_flowproduct').val(flow_product);
                func = 'ADD';
            }
            else{
                flow_product = product.replace(product_uri+';','');
                flow_product = flow_product.trim();
                $('#bt_flow').text('THEO DÕI SẢN PHẨM');
                $('#img_flow').hide();
                $('#tb_flowproduct').val(flow_product);
                func = 'DELETE';
            }
            if(flow_product.charAt(flow_product.length-1) == ';'){
                flow_product = flow_product.substring(0,flow_product.length-1);
                flow_product = flow_product.trim();
            }
            if(flow_user.charAt(flow_user.length-1) == ';'){
                flow_user = flow_user.substring(0,flow_user.length-1);
                flow_user = flow_user.trim();
            }
            $.post('~product/updateFlowProduct',{fullname:fullname, givenName: homepage, product : flow_product , flow_user:flow_user, property: property, func :func, value : product_uri} , function(data){
                //alert(data);
            });
        });
        $('#bt_flow_user').click(function(){
            var property = 'followUser';
            var func = '';
            var fullname = $('#tb_fullname').val();
            var homepage = $('#tb_homepage').val();
            var flow_product = $('#tb_flowproduct').val();
            var user = $('#tb_flowuser').val();
            var user_uri = $('#tb_uriuser').val();
            var flow_user = '';
            var sflow = $('#bt_flow_user').text();
            if(sflow == 'THEO DÕI NGƯỜI DÙNG'){
                flow_user = user.trim() + user_uri.trim()+';';
                $('#bt_flow_user').text('HỦY THEO DÕI');
                $('#img_flow_user').show();
                $('#tb_flowuser').val(flow_user);
                func = 'ADD';
            }
            else{
                flow_user = user.replace(user_uri+';','');
                flow_user = flow_user.trim();
                $('#bt_flow_user').text('THEO DÕI NGƯỜI DÙNG');
                $('#img_flow_user').hide();
                $('#tb_flowuser').val(flow_user);
                func = 'DELETE';
            }
            if(flow_product.charAt(flow_product.length-1) == ';'){
                flow_product = flow_product.substring(0,flow_product.length-1);
                flow_product = flow_product.trim();
            }
            if(flow_user.charAt(flow_user.length-1) == ';'){
                flow_user = flow_user.substring(0,flow_user.length-1);
                flow_user = flow_user.trim();
            }
            $.post('~product/updateFlowProduct',{fullname:fullname, givenName: homepage, product : flow_product, flow_user:flow_user, property: property, func :func, value : user_uri} , function(data){

            });
        });

        // image slide
        $('#banner-fade').bjqs({
            height      : 300,
            width       : 600,
            responsive  : true,
            animtype      : 'slide',
            automatic : true,
            thumbImage : true,
            nexttext    : '',
            prevtext    : '',
        });

        // Format description
        formatDescription();
        function formatDescription(){
            var imgs = $('.bjqs-markers img');
            var isRight = true;
            var i = 0;
            $('.detail_description br').each(function(index){
                if(i >= imgs.length){
                    return false;
                }
                var link = imgs.eq(i).attr('src');
                i++;
                var dis = $(this);  
                $img = $('<img/>');
                $img.load(function(){
                    $('<div class="shadow_img"><img src="' + link + '"></div>').insertBefore(dis);
                    dis.remove();
                }).attr('src',link);
            });
        }
    });
</script>

<div>
    <?php 
        $aParams = array('sCategoryUri' => $template->get('catelogy'));
        includeBlock('block/categoryMenuBlock' , $aParams); 
    ?>
    <div style="text-align: left;">
        <div style="display: none;">
            <input type="hidden" id="product_uri" value="<?php echo $template->get('uri');?>">
            <input hidden ="" id="tb_givenName" value="<?php echo $template->get('givenName'); ?>">
            <input hidden="true" id="tb_fullname" value="<?php echo $template->get('nameUser_login'); ?>">
            <input hidden=""  id="tb_homepage" value="<?php echo $template->get('homepage_login'); ?>">
            <input hidden="true" id="tb_flowproduct" value="<?php echo $template->get('flowProduct'); ?>"></input>
            <input hidden="true" id="tb_uriproduct" value="<?php echo $template->get('uri_product'); ?>">
            <input hidden="true" id="tb_flowuser" value="<?php echo $template->get('flowUser'); ?>">
            <input hidden="true" id="tb_uriuser" value="<?php echo $template->get('uri_userupload'); ?>">
            <input hidden="true" id="tb_img" value="<?php  if(isset($_SESSION['avatar'])){echo $_SESSION['avatar'];}?>">
            <input type="text" hidden="true" id="tb_masp" value="<?php echo $template->iId ?>">
        </div>
        <?php
            $username ='';
            if(isset($_SESSION['username']))
            {
                $username = $_SESSION['username'];
            }
        ?>
        <input type="text" id="tb_user" hidden="true" value="<?php echo $username ?>">
        <input type="text" id="tb_limit" hidden="true" value="10">
        <div style="float: left;width:600px;height:400px;">
            <!--  Outer wrapper for presentation only, this can be anything you like -->
            <div id="banner-fade" style="margin-top:20px;">
                <!-- start Basic Jquery Slider -->
                <ul class="bjqs">
                    <?php
                        if($template->get('images'))
                        {
                            foreach($template->get('images') as $image)
                            {
                                echo '<li><img src="'.URL::getLink('upload/'.$image).'"></li>';
                            }
                        }
                    ?>
                </ul>
                <!-- end Basic jQuery Slider -->
            </div>
            <!-- End outer wrapper -->
        </div>

        <div class="chitietspdivcontent">
            <div>   
                <!-- Like button --->
                <div id="heart" class="heart">
                    <input type="hidden" value="<?php echo $template->get('uri');?>">
                    <p><?php echo $template->get('totalLike'); ?></p>
                    <div class="heart_effect <?php echo ($template->get('isLiked') ? 'hear_active' : ''); ?>"></div>
                </div>
                <p class="chitietsptitile" style="font-size:24px;color:#4fb100;border-bottom:2px dashed #DDD;margin-right:32px;"><?php echo $template ->get('name') ?></p>
                <p>ĐƠN GIÁ : <span style="font-size:50px;color: red;text-shadow: 2px 2px 3px #999;font-weight:bold;"><?php echo number_format($template->get('dongia'),0,",",".");?></span> VNĐ 
                <p>Nhà Sản Xuât : <strong><a href="<?php echo $template ->get('manufacturer') ?>"><?php echo $template ->get('nameManufacturer') ?>  </a></strong> </p>
                <p>Upload By : <strong><a href="<?php echo $template ->get('nameUser_uri') ?>"><?php echo $template ->get('nameUser') ?> </a></strong> </p>
                <p>Địa Điểm : <strong><?php echo $template ->get('location') ?></strong></p> 
                <p> <label>Visitor :</label><label style="font-weight: bold;">  <?php echo $template ->get('viewTotal') ?></label></p>
                <p><label>Comment  :</label> <label style=" font-weight: bold;"> <?php echo $template ->get('viewComment') ?></label></p>
                <div class="follow_panel">
                    <div>
                        <?php
                            if(!$template->get('isOwnUser'))
                            {
                                if(isset($_SESSION['username']))
                                {
                                    if($template->get('is_Exit') =='')
                                    { ?>
                                    <p><a id="bt_flow" style="color: black;" href="javascript::void();">THEO DÕI SẢN PHẨM</a></p>
                                    <?php } else {?>
                                    <p><a id="bt_flow" style="color: black;" href="javascript::void();">HỦY THEO DÕI</a></p>  
                                    <?php }
                                }
                            }
                    ?></div>
                    <div>
                        <?php
                            if(isset($_SESSION['username']) && $_SESSION['user_uri'] != $template->get('uri_userupload') )
                            {
                                if($template->get('is_Exit_user') ==''){?>
                                <p><a id="bt_flow_user" style="color: black;color: red;" href="javascript::void();">THEO DÕI NGƯỜI DÙNG</a></p>
                                <?php } else {?>
                                <p><a id="bt_flow_user" style="color: black;color: red;" href="javascript::void();">HỦY THEO DÕI</a></p>
                                <?php }
                            }
                        ?>
                    </div>
                </div>
                <?php
                    if(!$template->get('isOwnUser'))
                    {
                        echo '<a id="bt_contact" val="'.$template->get('givenName').'" href="javascript:void(0);"></a>';
                    }
                ?>
            </div>
        </div>
    </div>
    <div style="clear: both;"></div>
    <h2 class="title red_style" style="margin-top:40px;">THÔNG TIN CHI TIẾT</h2>
    <div class="chitietspmota shadow">
        <p class="detail_description" style="margin: 0;padding:20px;line-height: 32px;"><?php echo nl2br($template ->get('motalong')); ?></p>
        <div style="clear: both;"></div>
    </div>

    <div style="clear: both;"></div>
    <?php if(count($template->get('listRelativeproduct')) > 0){ ?>
        <h2 class="title green_style" style="margin-top:20px">SẢN PHẨM ĐỀ XUẤT<a style="float: right;color:#FFF;margin-right:20px;" href="<?php echo URL::getLink('user/view/'.end(explode('/id/',$template->get('user_product')))) ?>">SẢN PHẨM CÙNG NGƯỜI ĐĂNG</a></h2>
        <?php } ?>
    <?php
        $aParams = array(
            'aProducts' => $template->get('listRelativeproduct')
        );
        includeBlock('block/slideProductBlock', $aParams); 
    ?>
    <div style="clear: both;"></div>
    <h2 class="title blue_style" style="margin-top:20px;">BÌNH LUẬN</h2>
    <div style="clear: both;"></div>
    <?php 
        $aParams = array(
            'product_id' => $template->iId,
        );
        includeBlock('chat/commentBlock', $aParams); 
    ?>
    <div style="clear: both;"></div>
</div>